home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 3_0 / DOUBLEDE / EXITADDR.C < prev    next >
C/C++ Source or Header  |  1988-06-22  |  3KB  |  93 lines

  1. #include <MacTypes.h>
  2. #include <OSUtil.h>
  3. #include <WindowMgr.h>
  4. #include <EventMgr.h>
  5. #include <DialogMgr.h>
  6.  
  7. #define     ETSTrapNum     0x1F4
  8.  
  9. showexitaddress()
  10. {
  11.     WindowPtr            w;
  12.     Rect                r;
  13.     long                address;
  14.     Str255                aStr;
  15.     long                timer;
  16.     
  17.     SetRect(&r,10,30,310,78);
  18.     SetPort(w = NewWindow(0L,&r,"\p",FALSE,1,-1L,FALSE,0));
  19.     TextFont(4); TextSize(12);
  20.     ShowWindow(w);
  21.         
  22.     strcpy(aStr,"ExitToShell() = $");
  23.     
  24.     address = NGetTrapAddress(ETSTrapNum,ToolTrap);
  25.     drawhex(&address,&aStr[strlen(aStr)],4,0);
  26.     
  27.     MoveTo(r.left+(r.right-r.left-TextWidth(aStr,0,strlen(aStr)))/2,24);
  28.     DrawText(aStr,0,strlen(aStr));
  29.     
  30.     strcpy(aStr,"(click mouse to continue)");
  31.     MoveTo(r.left+(r.right-r.left-TextWidth(aStr,0,strlen(aStr)))/2,36);
  32.     DrawText(aStr,0,strlen(aStr));
  33.  
  34.     timer = TickCount()+300L;
  35.     while(Button());
  36.     while( !Button() && (timer > TickCount()) );
  37.     while(Button());
  38.     
  39.     DisposeWindow(w);
  40.     FlushEvents(mDownMask,0);
  41. }
  42.  
  43. /****************************  drawhex  *****************************
  44.     srcPtr        address in memory, ie, &alongVariable or &anInt
  45.     dstPtr        (char *), with sufficient memory already allocated
  46.     numBytes    number of bytes to convert, ie, for a long, the
  47.                 value of 4 would normally be passed
  48.     pad            pass 1 if you want "AAAA AAAA",
  49.                 or 0 if you want "AAAAAAAA"
  50. *********************************************************************/
  51. drawhex(srcPtr,dstPtr,numBytes,pad)
  52. char    *srcPtr;
  53. char    *dstPtr;
  54. int        numBytes;
  55. int        pad;
  56. {
  57.     asm{
  58.         movem.l    A3-A4/D3-D4,-(SP)
  59.         move.w    pad,D4                ;do we pad every two bytes?
  60.         move.w    numBytes,D2            ;D2 = number of bytes to convert
  61.         move.l    dstPtr,A0            ;A0 -> destination area
  62.         move.l    srcPtr,A3            ;A3 -> source area
  63.         move.w    #0,D3                ;loop counter
  64.         lea        @thedata,A1            ;A1 -> hex digits table
  65.     @loop
  66.         move.b    (A3)+,D0            ;copy src-> into D0, increment src->
  67.         move.b    D0,D1                ;D1 = byte to convert
  68.         andi.w    #15,D1                ;mask off high nibble
  69.         move.b    0(A1,D1.w),1(A0)    ;copy D1th item in table to A0+1->
  70.         move.b     D0,D1                ;fresh copy of D0 for high nibble
  71.         lsr.w    #4,D1                ;move high nibble -> low nibble
  72.         move.b    0(A1,D1.w),0(A0)    ;copy D1th item in table to A0->
  73.         addi    #2,A0                ;increment    A0
  74.  
  75.         cmpi    #0,D4                ;do we pad the string?
  76.         beq        @nopadding
  77.  
  78.         addi    #1,D3                ;increment loop counter            
  79.         btst    #0,D3                ;is loop counter even?
  80.         bne        @nopadding            ;no, it is even, so...
  81.         move.b    #0x20,(A0)+            ;pad output with a space, incr dst->
  82.  
  83.     @nopadding
  84.         subi    #1,D2                ;decrement byte count
  85.         bne        @loop                ;loop if not
  86.         move.b    #0,(A0)                ;C string terminator character
  87.         movem.l    (SP)+,A3-A4/D3-D4    ;restore registers
  88.         return
  89.     @thedata
  90.         dc.b    '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
  91.     }
  92. }
  93.